import direct.directbase.DirectStart
from direct.task import Task
from direct.actor import Actor
from pandac.PandaModules import *
from direct.interval.MetaInterval import *
import math

import maultasche as mt

#for the events
from direct.showbase import DirectObject

from picker import Picker
from pcamera import CameraMover

mycam = CameraMover()
base.disableMouse()

##
##def CameraMover(task):
##    limit = [0.2, 0.2]
##    rate = 0.3
##    
##    if not base.mouseWatcherNode.hasMouse():
##        return Task.cont
##        
##    camx = base.camera.getX()
##    camy = base.camera.getY()
##    camz = base.camera.getZ()
##
##    maus = base.mouseWatcherNode.getMouse()
##    x = maus.getX()
##    y = maus.getY()
##
##    if x <= -1.0 + limit[0]:
##        base.camera.setPos(camx-rate, camy, camz)
##    if x >= 1.0 - limit[1]:
##        base.camera.setPos(camx+rate, camy, camz)
##    if y <= -1.0 + limit[0]:
##        base.camera.setPos(camx, camy-rate, camz)
##    if y >= 1.0 - limit[1]:
##        base.camera.setPos(camx, camy+rate, camz)
##
##    return Task.cont
##
##taskMgr.add(CameraMover, "CameraMover")

# Create Ambient Light
ambientLight = AmbientLight( 'ambientLight' )
ambientLight.setColor( Vec4( 0.3, 0.3, 0.3, 1 ) )
ambientLightNP = render.attachNewNode( ambientLight.upcastToPandaNode() )
render.setLight(ambientLightNP)

# Directional light 01
directionalLight = DirectionalLight( "directionalLight" )
directionalLight.setColor( Vec4( 1.0, 1.0, 1.0, 1 ) )
directionalLightNP = render.attachNewNode( directionalLight.upcastToPandaNode() )
# This light is facing backwards, towards the camera.
directionalLightNP.setHpr(225, -20, 0)
render.setLight(directionalLightNP)





#foonode = render.attachNewNode("foonode")
#fooActor = loader.loadModel("./models/officer_infantry")
fooActor = Actor.Actor("./models/officer_infantry")
fooUnit = mt.Unit(render, 0, "footman")
fooUnit.setPos(-10,0,1)
#fooActor = Actor.Actor("models/panda-model",{"walk":"models/panda-walk4"})
#fooActor.setScale(0.005,0.005,0.005)
fooActor.reparentTo(render)
fooActor.setPos(5, -5, 1)


mousePicker=Picker()

#load thest models
panda=loader.loadModel('zup-axis')
keep=loader.loadModel('./models/platform.egg')

#put them in the world
panda.reparentTo(render)
keep.reparentTo(render)
panda.setPos( 0, 0,0)
keep.setPos(20, 0, 1)

mousePicker.makePickable(keep)
mousePicker.makePickable(panda)
mousePicker.makePickable(fooActor)
mousePicker.makePickable(fooUnit)

foofont = loader.loadFont('cmr12.egg')
text = TextNode('node name')
text.setFont(foofont)
text.setText("foobar!")
textNodePath = fooActor.attachNewNode(text)
#textNodePath.setScale(0.07)

from direct.gui.OnscreenText import OnscreenText
textObject = OnscreenText(text = 'my text string',
    pos = (-0.9, 0.8), scale = 0.07, bg=(0.3,0.3,0.4,0.8))

run()